package com.example.sentinel_test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.csp.sentinel.annotation.SentinelResource;

@RequestMapping("/test")
@RestController
@SpringBootApplication
@EnableDiscoveryClient
public class SentinelTestApplication {

	@SentinelResource(value = "hello", blockHandler = "handleBlock", fallback = "handleFallback")
	@GetMapping("/hello")
	public String hello() {
		return "Hello, Sentinel!";
	}

	public String handleBlock(Throwable ex) {
		return "test wt : " + ex.getMessage();
	}

	public String handleFallback() {
		return "test fallback";
	}

	public static void main(String[] args) {
		SpringApplication.run(SentinelTestApplication.class, args);
	}

}
